<?php
namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Models\Machine;
use Dingo\Api\Http\Request;
use Illuminate\Support\Facades\DB;

class OperationController extends Controller
{
    protected $model;

    public function __construct(Machine $machine )
    {
        $this->model = $machine;
    }

    public function operationInfo(Request $request){
        $machineId = $request->machineId;

        $result = $this->model
            ->select('machines.*','admin_users.parent_id','admin_users.name','admin_users.phone')
            ->leftJoin('machine_managers','machine_managers.machine_id','=','machines.id')
            ->leftJoin('admin_users','admin_users.parent_id','=','machine_managers.manager_id')
            ->where('machines.id',$machineId)
            ->first();
        return $this->success($result);
    }
}
